{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def multiples_of_ten(start, stop):\n",
    "    \n",
    "\"\"\"\n",
    "  Returns a Tensor of dtype torch.float64 that contains all of the multiples of\n",
    "  ten (in order) between start and stop, inclusive. If there are no multiples\n",
    "  of ten in this range you should return an empty tensor of shape (0,).\n",
    "  \n",
    "  返回一个数据类型为torch.float64的张量，其中包含在开始和结尾（包含）之间的所有\n",
    "  10的倍数。如果该范围内没有10的倍数，则返回一个形状为（0，）的空张量。\n",
    "\n",
    "  Inputs:\n",
    "  - start, stop: Integers with start <= stop specifying the range to create.\n",
    "\n",
    "  Returns:\n",
    "  - x: Tensor of dtype float64 giving multiples of ten between start and stop.\n",
    "  \"\"\"\n",
    "    assert start <= stop\n",
    "  #############################################################################\n",
    "  #                    TODO: Implement this function                          #\n",
    "  #############################################################################\n",
    "  # Replace \"pass\" statement with your code\n",
    "    x = []\n",
    "    print(x)\n",
    "    for i in torch.arange(start,stop+1):\n",
    "        if(i%10 == 0):\n",
    "            x.append(i)\n",
    "    x = torch.tensor(x,dtype=torch.float64)\n",
    "  #############################################################################\n",
    "  #                            END OF YOUR CODE                               #\n",
    "  #############################################################################\n",
    "  return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([ 0,  1, 10,  3,  4,  5])\n",
      "tensor([10,  3,  4,  5])\n",
      "tensor([100,   1,   2,   3,   4,   5])\n",
      "3041243780480\n",
      "3041243780480\n",
      "3041243779456\n"
     ]
    }
   ],
   "source": [
    "a=torch.tensor([0,1,2,3,4,5])\n",
    "b=a[2:]\n",
    "c=a.clone()\n",
    "b[0]=10\n",
    "c[0]=100\n",
    "print(a)\n",
    "print(b)\n",
    "print(c)\n",
    "print(a.storage().data_ptr())\n",
    "print(b.storage().data_ptr())\n",
    "print(c.storage().data_ptr())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([1, 5, 7])\n"
     ]
    }
   ],
   "source": [
    "a = torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])\n",
    "print(a[[0,1,1],[0,0,2]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([3, 2, 1, 0])\n"
     ]
    }
   ],
   "source": [
    "x=torch.tensor([0,1,2,3])\n",
    "a=torch.arange(x.shape[0]-1,-1,-1)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[0.3998, 0.3943, 0.5559, 0.3950, 0.0277],\n",
      "        [0.5608, 0.3193, 0.2274, 0.8187, 0.9385],\n",
      "        [0.1028, 0.4477, 0.5916, 0.2279, 0.9061]])\n",
      "(tensor([[0.3998],\n",
      "        [0.5608],\n",
      "        [0.1028]]), tensor([[0.3943],\n",
      "        [0.3193],\n",
      "        [0.4477]]), tensor([[0.5559],\n",
      "        [0.2274],\n",
      "        [0.5916]]), tensor([[0.3950],\n",
      "        [0.8187],\n",
      "        [0.2279]]), tensor([[0.0277],\n",
      "        [0.9385],\n",
      "        [0.9061]]))\n",
      "[tensor([[0.3998],\n",
      "        [0.5608],\n",
      "        [0.1028]]), tensor([[0.3943],\n",
      "        [0.3193],\n",
      "        [0.4477]]), tensor([[0.5559],\n",
      "        [0.2274],\n",
      "        [0.5916]]), tensor([[0.3950],\n",
      "        [0.8187],\n",
      "        [0.2279]]), tensor([[0.0277],\n",
      "        [0.9385],\n",
      "        [0.9061]])]\n"
     ]
    }
   ],
   "source": [
    "#cross validation\n",
    "random = torch.rand(3, 5)\n",
    "print(random)\n",
    "x = random.chunk(5, 1)\n",
    "print(x)\n",
    "array = []\n",
    "for i in range(5):\n",
    "    array.append(x[i])\n",
    "print(array)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
